package com.korubo.web.contrller;

import com.korubo.web.model.Carousel;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.korubo.kit.R;
import com.korubo.web.service.CarouselService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (tb_carousel)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/carousel")
public class CarouselController {
    /**
     * 服务对象
     */
    @Resource
    private CarouselService carouselService;

    //list
    @PostMapping("list")
    public R list(@RequestBody(required = false) Carousel entity) {
        return carouselService.list(entity);
    }

    @PostMapping("add")
    public R add(@RequestBody Carousel entity) {
        entity.setId(UUID.fastUUID().toString());
        entity.setCreateTime(DateUtil.now());
        return carouselService.save(entity) ? R.ok() : R.fail();
    }

    @PostMapping("update")
    public R update(@RequestBody Carousel entity) {
        return carouselService.updateById(entity) ? R.ok() : R.fail();
    }

    @PostMapping("delete")
    public R delete(@RequestBody Carousel entity) {
        return carouselService.removeById(entity.getId()) ? R.ok() : R.fail();
    }

    @PostMapping("findById")
    public R findById(@RequestBody Carousel entity) {
        return R.ok(carouselService.getById(entity.getId()));
    }


}
